package cn.tedu.ems.studyvideo.controller;

import cn.tedu.ems.base.response.PageData;
import cn.tedu.ems.studyvideo.pojo.dto.VideoDTO;
import cn.tedu.ems.studyvideo.pojo.query.VideoQuery;
import cn.tedu.ems.studyvideo.pojo.vo.VideoCategory;
import cn.tedu.ems.studyvideo.service.VideoService;
import cn.tedu.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/v1/ems/video/")
@Api(tags = "视频管理")
public class VideoController {
    private static final Logger log = LoggerFactory.getLogger(VideoController.class);
    @Autowired
    private VideoService videoService;

    /**
     * 默认查找所有分类
     *
     * @return
     * @author: 蒋磊
     */
    @ApiOperation("视频分类查找")
    @GetMapping("category")
    public ResponseResult categorySelect() {
        log.debug("走这里了吗,走了");
        List<VideoCategory> videoCategories = videoService.categorySelect();
        return ResponseResult.ok(videoCategories);
    }


    /**
     * 接收前端条件四个,对应的Query类里的四个属性,其中type始终为2
     *
     * @return
     * @author: 蒋磊
     */
    @ApiOperation("查询视频列表")
    @GetMapping("list")
    public ResponseResult videoList(VideoQuery videoQuery) {
        log.debug("这是传输过来的type:{}", videoQuery);
        PageData data = videoService.videoList(videoQuery);
        log.debug("data:{}", data);
        return ResponseResult.ok(data);
    }

    /**
     * 这里是处理视频信息上传的,是前端传过来的文字数据
     *
     * @return
     * @author: 蒋磊
     */
    @ApiOperation("添加视频信息")
    @PostMapping("uploadData")
    public ResponseResult videoUploadData(VideoDTO videoDTO) {
        log.debug("videoDTO:{}", videoDTO);
        videoService.videoUploadData(videoDTO);
        return ResponseResult.ok();
    }

}
